package com.cat.dynamicPlanning02;

/**
*   @description https://leetcode.cn/problems/minimum-additions-to-make-valid-string/?envType=problem-list-v2&envId=dynamic-programming
*   @author 曲大人的喵
*   @create 2025/10/1 21:12
*   @since JDK17
*/

public class Solution13 {
    public int addMinimum(String word) {
        char[] s = word.toCharArray();
        int n = s.length, ans = s[0] - s[s.length - 1] + 2;
        for (int i = 1; i < n; i++) {
            ans += (s[i] - s[i - 1] + 2) % 3;
        }

        return ans;
    }
}
